package com.atguigu.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: Composite模式的组合类，可以管理College，根据类图可以看出 是通过聚合父类OrganizationComponent来实现聚合College的
 * @create: 2022-02-19 11:43
 **/
public class University extends OrganizationComponent{

    //list中放的是学院College: 通过聚合父类OrganizationComponent来实现聚合College的
    List<OrganizationComponent> organizationComponents = new ArrayList<OrganizationComponent>();

    public University(String name, String des) {
        super(name, des);
    }

    /**
     * 重写 add
     * @param organizationComponent 机构父类：此处为学院
     */
    @Override
    protected void add(OrganizationComponent organizationComponent) {
        organizationComponents.add(organizationComponent);
    }

    /**
     * 重写 remove
     * @param organizationComponent 机构父类：此处为学院
     */
    @Override
    protected void remove(OrganizationComponent organizationComponent) {
        organizationComponents.remove(organizationComponent);
    }

    /**
     * 输出University 包含的学院
     */
    @Override
    protected void print() {
        System.out.println("---------------" + getName() + "--------------");
        for (OrganizationComponent component : organizationComponents) {
            component.print();
        }
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public String getDes() {
        return super.getDes();
    }
}
